package cn.jaye.fabric.application;

import cn.jaye.fabric.application.command.CommonCommand;
import cn.jaye.fabric.common.constant.Global;
import cn.jaye.fabric.domain.service.RestTemplateService;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by Administrator on 2018/6/2.
 */
@Service
public class CommonApplicationService {

    @Autowired
    private RestTemplateService restTemplateService;


    public JSONObject list(CommonCommand commonCommand) {
        String url = Global.FABRRIC_GATEWAY_ADDRESS;
        if (commonCommand.getUrl().startsWith("/")) {
            url += commonCommand.getUrl();
        } else {
            url += "/" + commonCommand.getUrl();
        }
        JSONObject postData = commonCommand.getArgs();
        JSONObject resultObject = restTemplateService.getUrlResponse(url, postData);
        return resultObject;
    }
}
